package com.ziyia.vierpager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;



public class MyAdapter extends FragmentStateAdapter {
    // 存储的是fragment布局
    private List<Fragment> fragments;


    // 我们在原来的基础上，加上一个参数，用于接收fragment布局
    public MyAdapter(@NonNull @NotNull FragmentManager fragmentManager, @NonNull @NotNull Lifecycle lifecycle, List<Fragment> fragments) {
        super(fragmentManager, lifecycle);
        // 将接收到的布局设置到成员变量上
        this.fragments = fragments;
    }

    /**
     * 创建fragment布局
     * @param position
     * @return
     */
    @NonNull
    @org.jetbrains.annotations.NotNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    // 布局的个数
    @Override
    public int getItemCount() {
        return fragments.size();
    }
}
